using log4net.Config;
using Rubikev.Common;
using Rubikev.Common.Data;
using Rubikev.Common.DependencyInjection;
using Rubikev.NHibernate;
using Rubikev.StructureMap;
using Rubikev.Test.Common;

namespace Rubikev.Rockface.NHibernate.Test
{
   /// <summary>
   /// Base class for entity Crud, to set up persistence layer, etc.
   /// </summary>
   /// <typeparam name="TEntity">The type of entity under test</typeparam>
   public abstract class RockfaceCrudTestBase<TEntity> : EntityCrudTestBase<TEntity> 
      where TEntity : class, IEntity, new()
   {
      /// <summary>
      /// Sets up NHibernate and StuctureMap registries
      /// </summary>
      protected override void RegisterTypes()
      {
         // Scan the current directory for registrations
         var appConfig = new ApplicationConfiguration();
         appConfig.OnStarting();

         // Setup the NHibernate and StructureMap specific references
         typeProvider = new TypeProvider();
         var typeRegister = TypeProvider.GetInstance<ITypeRegister>();
         typeRegister.RegisterType<ISession, SessionAdapter>(LifetimeScope.Instance);

         XmlConfigurator.Configure();
      }

      private ITypeProvider typeProvider;

      /// <summary>
      /// Gets the type provider
      /// </summary>
      protected override ITypeProvider TypeProvider { get { return typeProvider; } }
   }
}